// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import FastClick from 'fastclick'
import VueRouter from 'vue-router'
import store from './store'
import routerMap from './router'
import Util from './util/common'
import 'lib-flexible' // 弹性布局

const App = () => import('./App')

Vue.use(VueRouter)
/** 路由配置 */
const router = new VueRouter(routerMap)
router.beforeEach(function (to, from, next) {
  // loading
  let showLoading = true
  store.commit('updateCommon', {
    isLoading: showLoading
  })
  // 调试模式加载vconsole
  if (to.query.debug === '1') {
    Util.loadJS({
      path: '../static/libs/vconsole.min.js',
      callback: function () {
        new VConsole() // eslint-disable-line
      }
    })
  }
  next()
})
router.afterEach(function (to, from) {
  // loading
  let showLoading = to.meta.isLoading || false
  store.commit('updateCommon', {
    isLoading: showLoading
  })
  // 改标题
  if (to.meta.title) {
    document.title = to.meta.title
  }
})
/** 移动端点击延迟 */
FastClick.attach(document.body)
/** 阻止 vue 在启动时生成生产提示 */
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app-box')
